package cn.tedu.demo;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class testtest {
    public static void main(String[] args) throws ParseException {
        String checkinDateString="2023-03-01";
        String checkoutDateString="2023-03-03";
        Date checkinDate= new SimpleDateFormat("yyyy-MM-dd").parse(checkinDateString);
        Date checkoutDate= new SimpleDateFormat("yyyy-MM-dd").parse(checkoutDateString);
        System.out.println("checkinDate"+checkinDate);
        System.out.println("checkoutDate"+checkoutDate);
        //计算天数为  (date1.getTime() - date2.getTime()) / (24*60*60*1000) + 1;
        //但酒店入住与离店的日期计算的天数要-1天
        //+1-1=0,下面表达式为简略后结果
        long day = (checkoutDate.getTime() - checkinDate.getTime()) / (24*60*60*1000);
        System.out.println("预定天数:"+day);
    }
}
